<template>
  <div class="goods-list">
    <!-- <router-link
      :to="'/home/goodsinfo/'+item.id"
      class="goods-item"
      v-for="item in goodsList"
      :key="item.id"
      tag="div"
    >
      <img :src="item.img_url" alt />
      <h4 class="title">{{item.title}}</h4>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.sell_price}}</span>
          <span class="old">￥{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </router-link>-->
    <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="getDetail(item.id)">
      <img :src="item.img_url" alt />
      <h4 class="title">{{item.title}}</h4>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.sell_price}}</span>
          <span class="old">￥{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      goodsList: [
        {
          id: 10,
          title: "小米(Mi)小米Note 16G双网通版",
          add_time: new Date().toLocaleString(),
          zhaiyao: "",
          click: "6",
          img_url:
            "//img.alicdn.com/tps/i1/O1CN013yL3ad29zFljHDY12_!!0-juitemmedia.jpg_560x370Q50s50.jpg_.webp",
          sell_price: 2799,
          market_price: 2999,
          stock_quantity: 60
        },
        {
          id: 11,
          title: "包邮进口Chabatree无铅玻璃木柄酱汁杯蜂蜜牛奶零食碗迷你蘸酱碗",
          add_time: new Date().toLocaleString(),
          zhaiyao: "",
          click: "3666",
          img_url:
            "//gw.alicdn.com/bao/uploaded/i2/858389760/TB2gzOPmstnpuFjSZFvXXbcTpXa_!!858389760.jpg_500x500q90.jpg_.webp",
          sell_price: 64.99,
          market_price: 123.99,
          stock_quantity: 3216
        },
        {
          id: 12,
          title: "真维斯男士潮牌韩版宽松直筒牛仔裤",
          add_time: new Date().toLocaleString(),
          zhaiyao: "",
          click: "520",
          img_url:
            "//img.alicdn.com/tps/i2/O1CN01abKVEV2AX94sLHgFm_!!0-juitemmedia.jpg_560x370Q50s50.jpg_.webp",
          sell_price: 120,
          market_price: 216,
          stock_quantity: 66
        }
      ]
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.goodsList = this.goodsList;
    },
    getMore() {
      alert("加载更多功能还在痛苦挣扎中...");
    },
    getDetail(id) {
      //1.最简单的跳转
      // this.$router.push("/home/goodsinfo/" + id);
      //2.传递对象
      console.log(this);
      // this.$router.push({path:"/home/goodsinfo/" + id})
      //3.传递命名的路由
      this.$router.push({ name: "goodsinfo", params: { id: id } });
    }
  }
};
</script>
<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  padding: 7px;
  justify-content: space-between;
  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 3px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }
    .info {
      background-color: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
}
</style>